package com.jzone.teacherajax.service.impl;

import com.github.pagehelper.PageHelper;
import com.jzone.teacherajax.mapper.TeacherMapper;
import com.jzone.teacherajax.pojo.Teacher;
import com.jzone.teacherajax.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public void add(Teacher teacher) {
        teacherMapper.add(teacher);
    }

    @Override
    public void update(Teacher teacher) {
        System.out.println("Updating Teacher: " + teacher);
        teacherMapper.update(teacher);
    }

    @Override
    public void delete(Integer id) {
        teacherMapper.delete(id);
    }

    @Override
    public List<Teacher> getAllTeachers(int page, int size) {
        System.out.println("Setting page: " + page + ", size: " + size);
        PageHelper.startPage(page, size); // 设置分页
        List<Teacher> teachers = teacherMapper.getAllTeachers(); // 返回分页后的结果
        System.out.println("Fetched teachers: " + teachers.size());
        return teachers;
    }

    @Override
    public Teacher getTeacherByEmployeeId(Integer id) {
        return teacherMapper.getTeacherByEmployeeId(id);
    }

    @Override
    public int getTeacherCount() {
        return teacherMapper.getTeacherCount();
    }

}
